package com.example.mapstructdemo;


import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;


/**
 * 拷贝的对象中的有属性是集合的情况
 */

@Mapper
public interface TeacherMapper {

    TeacherMapper INSTANCE = Mappers.getMapper(TeacherMapper.class);
    @Mapping(source = "gender.name", target = "gender")
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss")
    TeacherVO teacher2TeacherVO(Teacher teacher);

    /**
     * 对于不满足的字段或者需要单独特殊处理的字段可以使用扩展的方法
     */
    default TeacherVO convertTeacherExtDTO(Teacher teacher) {
        if( teacher == null) {
            return  null;
        }

        TeacherVO teacherVO = teacher2TeacherVO(teacher);
        teacherVO.setCar(teacher.getCar());
        return teacherVO;
    }
}
